package tech.senri.iot.socket.service.socket

import io.netty.channel.Channel
import tech.senri.iot.socket.model.RequestMessage

object SessionManager
{

    private val sessionMap = mutableMapOf<String, Channel>()


    fun setSession(deviceId: String, channel: Channel)
    {
        sessionMap[deviceId] = channel
    }

    fun sendMessage(message: RequestMessage)
    {
        message.deviceId?.let {
            if (sessionMap.contains(it))
            {
                val session = sessionMap.getValue(it)
                session.writeAndFlush(message)
            }
        }
    }
}
